<?php
//echo "POST: ";
//print_r($_POST);
//echo "<BR>GET: ";
//print_r($_GET);
$dateYear = date(Y)+543;
if(isset($_GET['numSearch'])){
    $num = $_GET['num'];
    $type = $_GET['type'];
//    echo "num: ".$num." AND type: ".$type;
    if($type=='regisid'){
        $sql = "SELECT * FROM regis WHERE $type='$num' AND eduyear=$dateYear";
    }else if($type=='citizenid'){
        $sql = "SELECT r.regisid regisid FROM regis r,study stu WHERE r.studyid = stu.studyid AND stu.citizenid='$num' AND eduyear=$dateYear";
    }
        $query = mysql_query($sql);
        $result = mysql_fetch_array($query);
        $regisid = $result['regisid'];
        echo "<BR>regisid: ".$regisid;
?>
<script>
        window.location="/regisonline/template?phppage=editRegisForm.php&regisid=<?=$regisid?>";
</script>    
<?          
}else if(isset($_GET['nameSearch'])){
    $firstName = $_GET['firstName'];
    $lastName = $_GET['lastName'];
//    echo "firstName: ".$firstName." AND lastName: ".$lastName;
    $sql = "SELECT r.regisid regisid FROM regis r,study stu WHERE r.studyid = stu.studyid AND stu.firstname='$firstName' AND stu.lastname='$lastName' AND r.eduyear=$dateYear";
    $query = mysql_query($sql);
    $result = mysql_fetch_array($query);
    $regisid = $result['regisid'];
//    echo "<BR>".$sql;
//    echo "<BR>mysql_row: ".mysql_num_rows($query);
    echo "<BR>regisid: ".$regisid;
?>
<script>
        window.location="/regisonline/template?phppage=editRegisForm.php&regisid=<?=$regisid?>";
</script>    
<?      
}else{
?>
<script>
    alert("เข้าระบบไม่ถูกต้อง");
    window.close();
</script>
<?
}
?>
